// 信息提示
function msg(title, duration = 1500, mask = false, icon = 'none') {
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}

// 获取页面栈
function getPage() {
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}

// 时间格式化
function filterTime(msec){
	const time = new Date(Number(msec));
	const year = time.getFullYear(); //年
	const month = time.getMonth() + 1; //月
	const day = time.getDate(); //日
	const hour = time.getHours(); //时
	const minute = time.getMinutes(); //分
	const second = time.getSeconds(); //秒
	return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}

// 获取节点数据
function getNodes(that, str, num){
	let arr = [];
	const query = uni.createSelectorQuery().in(that);
	// console.log(query)
	if(num == 1){
		setTimeout(() => {
			query.select(str).boundingClientRect(data => {
				arr.push(data);
				// console.log("得到布局位置信息" + JSON.stringify(data));
				// console.log("节点离页面顶部的距离为" + data.top);
			}).exec();
		}, 100)
	} else{
		setTimeout(() => {
			query.selectAll(str).boundingClientRect().exec((res)=>{
				let nodes = res[0];
				nodes.map(item => {
					arr.push(item);
				})
				// console.log(data)
			});
		}, 100)
	}
	return arr
}

// 数值转化
function getFloat(figure){
	// let str = figure + '';
	if (!figure){
		return (0).toFixed(2);
	} else{
		let num = figure * 1;
		// console.log(num)
		if (num != 0){
			return figure;
		}else{
			return num.toFixed(2);
		}
	}
}

// 获取币种参数
function getType(num){
	if (num == 7){
		return {
			typeName: 'FIL',
			curImg: '/static/pages/filecoin.png'
		}
	} else if(num == 4){
		return {
			typeName: 'USDT',
			curImg: '/static/pagesB/usdt.png'
		}
	} else if(num == 6){
		return {
			typeName: 'ETH',
			curImg: '/static/pagesC/eth.png'
		}
	} else{
		return {
			typeName: 'BTC',
			curImg: '/static/pagesC/btc.png'
		}
	}
}

// 获取币种列表
function getMoney(list, wallet){
	let arr = list.map(item => {
		if(item.title == 'FIL'){
			return{
				...item,
				'24H_shouyi': wallet['24H_shouyi'],
				fil_money: getFloat(wallet.total_fil_money),
				money: getFloat(wallet.fil_money * 1),
			}
		} else if(item.title == 'USDT'){
			return{
				...item,
				money: getFloat(wallet.usdt_money)
			}
		} else if(item.title == 'ETH'){
			return{
				...item,
				money: getFloat(wallet.eth_money)
			}
		} else{
			return{
				...item,
				money: getFloat(wallet.btc_money)
			}
		}
	})
	return arr
}

// 导出
export {
	msg,
	getPage,
	filterTime,
	getType,
	getFloat,
	getMoney,
	getNodes
}